package Spring.cn.edu.scau.cmi.lishuoxin.client;

import org.springframework.context.ApplicationContext;

import Spring.cn.edu.scau.cmi.lishuoxin.bean.Student;
import Spring.cn.edu.scau.cmi.lishuoxin.bean.Teacher;
import Spring.cn.edu.scau.cmi.lishuoxin.util.SpringUtil;
import javafx.application.Application;
import javafx.geometry.Insets;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.control.Label;
import javafx.scene.layout.VBox;
import javafx.scene.text.Font;
import javafx.scene.text.FontWeight;
import javafx.scene.layout.Pane;
import javafx.stage.Stage;

public class SpringClient extends Application {

	@Override
	public void start(Stage primaryStage) throws Exception {

		Pane pane = new Pane();
		VBox vBox = new VBox();
		
		vBox.setPadding(new Insets(50,50,50,50));
		vBox.setSpacing(20);
		Label lbl = new Label("点击获取信息");
        lbl.setFont(Font.font("Amble CN", FontWeight.BOLD, 24));
        vBox.getChildren().add(lbl);
		
		Button button1 = new Button("学生信息");
		button1.setOnAction(e->getStudent());
		Button button2 = new Button("老师信息");
		button2.setOnAction(e->getTeacher());
		vBox.getChildren().addAll(button1,button2);
		pane.getChildren().add(vBox);
		
		Scene scene = new Scene(pane,300,300);
		primaryStage.setTitle("Spring框架客户端");
		primaryStage.setScene(scene);
		primaryStage.show();
	}
	
	private AlertBox alertBox = new AlertBox();
	
	public void getStudent() {
		ApplicationContext ac = SpringUtil.getContext();
		Student student = (Student) ac.getBean("lsx");
		alertBox.display(student.toString());
	}

	public void getTeacher() {
		ApplicationContext ac = SpringUtil.getContext();
		Teacher teacher = (Teacher) ac.getBean("lzq");
		alertBox.display(teacher.toString());
	}
	
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		launch(args);
	}
}
